<?php
/**
 * 功能描述：	前端公共部分
 * @datetime	2022-08-08
 * @version   	v2.3.0
 * @author   	ZHL
 * @copyrigh  	2022 ZHL 版权所有
 */

class Web_BaseController extends Controller {

    public function __construct($controller, $action)
    {
        parent::__construct($controller, $action);
        $controllerArr = explode('_', $controller);
        $controller = strtolower(end($controllerArr));
        $this->temp_controller = $controller;
        $this->temp_action = strtolower($action);
    }

    /**
     * Notes:前端入口方法-智能映射模版
     */
    public function index(){
        $data['param'] = Fun::input();
        //$this->set('param', $data);
        $data = is_array($data['param']) ? array_merge($data, $data['param']) : $data;
        foreach($data as $k=>$v){
            $this->set($k, $v);
        }

        //$this->set('tmplUrl', $this->temp_controller);
        //$this->set('title', $this->temp_controller);
        // 映射模版
        $temp = str_replace(array('\/','/'),'', $GLOBALS['ADMIN']['web_temp_p']).'/'.$this->temp_controller;
        if($GLOBALS['ADMIN']['web_temp_flag'] == 1){
            if($GLOBALS['ADMIN']['web_temp_m']){
                if(isMobile()){
                    $temp = str_replace(array('\/','/'),'', $GLOBALS['ADMIN']['web_temp_m']).'/'.$tempName;
                }
                $port = isset($data['param'][SYS_URL_FIX_PORT]) ? $data['param'][SYS_URL_FIX_PORT] : 0;
                if($port == 2){
                    $temp = str_replace(array('\/','/'),'', $GLOBALS['ADMIN']['web_temp_m']).'/'.$tempName;
                }
            }
        }
        $this->display($temp);
    }

    /**
     * Notes:提交留言
     * User: ZHL
     * Date: 2020/9/28
     */
    public function msg(){
        header("Access-Control-Allow-Origin: *");

        $mould = Fun::input('mould');
        $menu_id = Fun::input('menu_id', 0, 'd');
        $dayCount = Fun::input('daycount', 10, 'd'); // 一天提交多少次，0不限

       /* $param['message_name'] = Fun::input('name');
        $param['message_tel'] = Fun::input('tels');
        $param['message_con'] = Fun::input('cont');*/
        $param = Fun::input();
        $result = Web_BaseServe::addMssage($param, $mould, $menu_id, $dayCount);
        Fun::json($result, true);
    }

    /**
     * Notes: 分页公共方法
     * Type: 动态分页通用
     * User: ZHL
     * Date: 2020/9/29
     */
    function pagelists(){
        $mould = Fun::input('m');
        $menu_id = Fun::input('c');
        $page = Fun::input('page','d');
        $result = Web_BaseServe::pageLists($mould, $menu_id, $page);
        $page = '';
        if($result['code'] == 10000 && !empty($result['page'])){
            $page = $result['page']['f'];
            $page .= $result['page']['p'];
            $page .= $result['page']['s'];
            $page .= $result['page']['n'];
            $page .= $result['page']['l'];
            $page .= $result['page']['i'];
        }
        $this->set('lists', $result['data']);
        $this->set('pages', $page);
        $this->display();
    }

    /**
     * Notes:分页公共
     * Type: Ajax异步分页/持异步无限加载
     * User: ZHL
     * Date: 2020/9/29
     */
    function pagelistsajax(){
        $param = Fun::input('param');
        $result = Web_BaseServe::pageListsAjax($param);
        Fun::json($result, true);
    }

    /**
     * Notes:阅读统计
     * User: ZhuHaili
     */
    public function readcount(){
        $essayId = Fun::input('essay_id');
        $mouldCode = Fun::input('mould_code');
        $result = Web_BaseServe::readCount($mouldCode, $essayId);
        Fun::json($result, true);
    }

    /**
     * Notes: 文章踩赞更新
     * User: ZhuHaili
     * Date: 2020/11/6
     */
    function essayops(){
        header("Access-Control-Allow-Origin: *");
        $mould = Fun::input('mould');
        $id = Fun::input('id');
        $type = Fun::input('type');
        $result = Web_BaseServe::essayOpsCount($mould, $id, $type);
        Fun::json($result, true);
    }

    /**
     * Notes: 文章赞踩数据获取
     * User: ZhuHaili
     * Date: 2020/4/9
     */
    function essaysupport(){
        header("Access-Control-Allow-Origin: *");
        $mould = Fun::input('mould');
        $id = Fun::input('id');
        $result = Web_BaseServe::essaySupportCount($mould, $id);
        Fun::json($result, true);
    }
}